from public.pages.basepage import BasePage
from selenium import webdriver
from public.utils.read_ini import Read_ini
from config.config import *
import os
from time import sleep
from data.input_elem import Tpshop_elems
from ddt import ddt,file_data

file2=os.path.join(data_path,"coupon.json")
file=os.path.join(data_path,"data.ini")
r=Read_ini(file)
url=r.read_ini_data("tpshop_data","url2")
admin=r.read_ini_data("tpshop_data","adminname")
passwd=r.read_ini_data("tpshop_data","adminpasswd")
verify=r.read_ini_data("tpshop_data","adminverify")

@ddt()
class Add_Onsale(BasePage):
    @file_data(file2)
    def test_001(self, name, money, condition, createnum):
        driver=webdriver.Chrome()
        BasePage.set_driver(driver)
        BasePage.max()
        a=BasePage.get_driver()
        a.get(url)
        sleep(5)
        elme1=BasePage.search_elem(Tpshop_elems.admin_name)
        BasePage.sendkeys(elme1,admin)
        elem2=BasePage.search_elem(Tpshop_elems.admin_passwd)
        BasePage.sendkeys(elem2,passwd)
        elem3=BasePage.search_elem(Tpshop_elems.admin_verify)
        BasePage.sendkeys(elem3,verify)
        elem4=BasePage.search_elem(Tpshop_elems.surebtn)
        BasePage.click(elem4)
        sleep(2)
        elem5=BasePage.search_elem(Tpshop_elems.shop)
        BasePage.click(elem5)
        sleep(1)
        elem6=BasePage.search_elem(Tpshop_elems.onsale)
        BasePage.click(elem6)
        sleep(2)
        elem7=BasePage.search_elem(Tpshop_elems.juan)
        BasePage.click(elem7)
        sleep(3)
        elem8=BasePage.search_elem(Tpshop_elems.iframe2)
        BasePage.switch_frame(elem8)
        elem9=BasePage.search_elem(Tpshop_elems.add_juan)
        BasePage.click(elem9)
        sleep(1)
        ELEM1=BasePage.search_elem(Tpshop_elems.juan_name)
        BasePage.sendkeys(ELEM1,name)
        sleep(1)
        ELEM2=BasePage.search_elem(Tpshop_elems.juan_money)
        BasePage.sendkeys(ELEM2,money)
        sleep(1)
        ELEM3=BasePage.search_elem(Tpshop_elems.spend_money)
        BasePage.sendkeys(ELEM3,condition)
        sleep(1)
        ELEM4=BasePage.search_elem(Tpshop_elems.juan_count)
        BasePage.sendkeys(ELEM4,createnum)
        sleep(1)
        ELEM5=BasePage.search_elem(Tpshop_elems.juan_status)
        BasePage.click(ELEM5)
        sleep(1)
        ELEM6=BasePage.search_elem(Tpshop_elems.juan_btn)
        BasePage.click(ELEM6)
        sleep(2)








if __name__ == '__main__':
    import unittest
    unittest.main()
